<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            width: 80px;
            height: 20px;
            background: chocolate;
            border-radius: 3px;
            filter: drop-shadow(3px 3px 1px);
            text-align: center;
        }
        /*div:hover{*/
        /*    transform: scale(1.2,1.2);*/
        /*}*/
        div:active{
            transform: translate(2px,2px);
        }
        span:after{
            content: '\26fa';
            font-size: 360px;
        }
    </style>
</head>
<body>
<div>button</div>
<span>123</span>
</body>
<script>
    $.post("/user/login",{username:"usernmae",password:"password"},function(data){
        if(data.code == 200){
            var token = data.result.token;
            var userId = data.result.userId;
            //保存到session中
            sessionStorage.setitem("USERID",token);
            sessionStorage.setItem("TOKEN",userId);
            // cookie;  path expire 有效期 随http请求\响应流转
        }else if(data.code == 401) {
            location.href = "/login.html";
            return;
        }else{
            alert(data.msg);
        }
    });

    //带请求头的请求方式
    $.ajax({
        url:'/user/info',
        type:'get',
        dataType:'json',
//nodejs  用js开发后台程序 javascript  > typescript ts
        //　grpc  golang ,java ,c ,c#,python,
        headers:{//方法一
            TOKEN:sessionStorage.getItem("token"),
            USERID:sessionStorage.getItem("userId"),
            contentType:"application/json",
        },
        beforeSend:function(xhr){//方法二
            xhr.setHeaderValue("TOKEN",sessionStorage.getItem("token"));
            xhr.setHeaderValue("USERID",sessionStorage.getItem("userId"))
        },
        success:function(data){
            //业务处理
        }
    })
</script>
</html>